//Thanks to someone[Donno who!] for this function
function init_php_file_tree() {
  var aMenus, mclass, submenu, node, d, i, j;
	if (!document.getElementsByTagName) { return; }
	aMenus = document.getElementsByTagName("LI");
	for (i = 0; i < aMenus.length; i++) {
		mclass = aMenus[i].className;
		if (mclass.indexOf("pft-directory") > -1) {
			submenu = aMenus[i].childNodes;
			for (j = 0; j < submenu.length; j++) {
				if (submenu[j].tagName == "A") {
					submenu[j].onclick = function() {
						node = this.nextSibling;
											
						while (1) {
							if (node !== null) {
								if (node.tagName == "UL") {
									d = (node.style.display == "none")?true:false;
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "open" : "closed";
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					};
					
					submenu[j].className = (mclass.indexOf("open") > -1) ? "open" : "closed";
				}
				
				if (submenu[j].tagName == "UL"){
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
					}
			}
		}
	}
	return false;
}

function getSubfolders(parentElement) {
  $.ajax({
    type: "get",
    url: "modules/common/getsubfolders.php",
    data: "t=" + new Date() + getCheckedQstring('files[]').querystring + "&dir=" + $("#currentdir").val(),
    dataType: "html",
    success: function(data) {
      //alert(data);
      $(parentElement).html(data);
      init_php_file_tree();
      $("input[type='radio']:first").attr("checked", "checked");
    }
  });
}
